﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AgencyEntityLib.BaseEntity;
using Grishko.DataTier;
using OutdoorLib.BaseEntity;
using OutdoorLib.BaseEntity.WS;
using OutdoorLib.BaseEntity.Agency;
using OutdoorLib.BaseEntity.Dictionary;
using OutdoorLib.BaseEntity.Face;
using Ecopsy.Tools;
using OutdoorLib.BaseEntity.Provider;

namespace OutdoorLib.Context
{
    public class AgencyLib_GlobalConstants : DataTierConstants
    {
        public static  Func<string> _getAgencyId;
        //public static Func<Agency> _getAgency;

        public static  readonly DateTime MaxDate = DateTimeTools.MaxDate ;
        public static readonly DateTime MinDate = DateTimeTools.MinDate ;

        public static string qProxyId { get { return TreeEntitySingle.qProxyId; } }

        public const string qPrefNEW_RECORD = "NEW_RECORD";
        public const string qID = "ID";
        public const string qTagName = "TagName";

        

        #region  Типы скидок
        public const string DiscountType_Discount = "77D0FBAD-A1EB-445D-A816-EE91262E60C5";
        public const string DiscountType_Nachislenie = "A1B072B7-0415-4D06-8662-F30C57AB8110";
        #endregion

        

        #region Типы контактов
        /// <summary>
        /// Типы папок для хранения древовидных справочников
        /// </summary>
        public const string Contact_Phone = "490A1955-995D-4984-A22B-24DF3AC5B5EB";
        //public const string Contact_Email = "AB2DBDAA-352B-467D-8B51-0B4C57E3D08F";
        public const string Contact_Url = "6939D823-0A4C-47FC-BF3E-6EABF48C15C5";
        public const string Contact_Adress = "E37D5E04-CA19-421D-A729-8FE640E1AA57";
        #endregion

        #region типы хранимых справочников 
        /// <summary>
        /// Папка системных справочников 
        /// </summary>
        /// 
        public const string TreeDictionaryFolderType_System = "D556BF06-A0FE-45E5-832F-51822FCF4409";
        //public const string TreeDictionaryFolderType_Users = "E75ADCA7-8E50-4D58-897C-3849E5C773E7";
       
        
        /// <summary>
        /// Категории древовидных справочников. DictionaryTypeID для табички dictionary
        /// </summary>
        public const string TreeDictionaryType = "80125050-C632-4769-BFE2-BAED31E22986";
        /// <summary>
        /// 
        /// </summary>
        public const string DictionaryPageType = "D5AB6916-BDA5-4FEC-9CC2-CD2F15A1F278";
        
        #endregion

        #region Категори справочников        
            /// <summary>
        /// Справочник типов контрактов (контракт, бронированиеЮ самореклама)
        /// </summary>
        public const string Dictionary_ContractType = "7165E6C0-4F56-4621-BA19-0A3838484DF1";
            
        #endregion
       
        #region Категории древовидных справочников

        /// <summary>
        /// Справочник типов конструкций 
        /// </summary>
        public const string TreeDictionary_ConstractionType = "3E5A3086-2A46-4051-9CE8-934976E40AC8";
        /// <summary>
        /// справочник адресная программа
        /// </summary>
        public const string TreeDictionary_AdressProgram = "991F97B3-6314-413D-9FD1-24157CF0479D";

        /// <summary>
        /// справочник улицы
        /// </summary>
        public const string TreeDictionary_Streets = "EFB070F5-D940-4228-BE7B-08036D0E1BEC";

        /// <summary>
        /// справочник ограничения носителя
        /// </summary>
        public const string TreeDictionary_ConstractionConditions = "ED90F24F-2177-4121-9600-FD0F4A978C55";

        /// <summary>
        /// справочник - географическая привязка привяка
        /// </summary>
        public const string TreeDictionary_GeoBinding = "BADB2B14-9D6C-4C69-9EDD-8D5831009852";

        /// <summary>
        /// справочник транспортное положение конструкции
        /// </summary>
        public const string TreeDictionary_LocationDescribe = "45A6FF02-E731-4D4F-906E-DE2943E82A1D";

        /// <summary>
        ///  Категория клиента (дерево - специализации)
        /// </summary>
        public const string TreeDictionary_ClientsCategory = "CF128840-C898-41D1-8F68-042287F9B054";

        
        /// <summary>
        /// Статус клиента (потенциальный клиент и т.п.)
        /// </summary>
        public const string TreeDictionary_ClientStatus = "1BEAA476-1462-48C0-8000-72AEE2F99592";


        /// <summary>
        /// Категории задач
        /// </summary>
        public const string TreeDictionary_TaskCategory = "B5F499C5-B48B-4B0B-AB2B-73320C746B53";
        
        #endregion

        #region ключи SiteMap
        public const string SiteMapItem_iSales_Contract = "iSales_Contract";

        public const string SiteMapItem_SysDictionary_Frame = "SysDictionary_Frame";
        public const string SiteMapItem_iFrameAdmin_SurfaceGroups = "iFrameAdmin_SurfaceGroups";
        public const string SiteMapItem_iFrameAdmin_iFrameAdmin_Discounts = "iFrameAdmin_Discounts";
        public const string SiteMapItem_iFrameAdmin_iFarmeAdmin_AdressPrograms = "iFarmeAdmin_AdressPrograms";
        public const string SiteMapItem_iFrameAdmin_Constractions = "iFrameAdmin_Constractions";
        public const string SiteMapItem_iFrameAdmin_ConstractionEditor = "iFrameAdmin_ConstractionEditor";
        public const string SiteMapItem_iFrameAdmin_EditDiscount = "iFrameAdmin_EditDiscount";
        public const string SiteMapItem_Agency_Frame = "Agency_Frame";
        public const string SiteMapItem_EditDepartments = "EditDepartments";
        public const string SiteMapItem_MangeTask = "MangeTask";
        
        #endregion

        /// <summary>
        /// Проверить id - если есть префикс - объект новый 
        /// Если нет префикса - обратиться к Кэшу,БД - поискать - не найден - объект новый        
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static bool IsNewRecord(string ID)
        {
            if(ID.IndexOf(qPrefNEW_RECORD) > -1)
                return true;

            //if (null != CacheTools.GetSessionCacheObect(GetNewID(ID)))
            //                    return true;
            

            object res=  SqlTools.ExecuteSqlText( string .Format ("select count(*)  from dbo.vSrchStorageLinks where id='{0}'",ID.Replace (qPrefNEW_RECORD,"") ));

            return Convert .ToInt16 (res) == 0;
        }

        public static string GetID(string ID)
        {
            return ID.Replace(qPrefNEW_RECORD, string.Empty);
        }
        
        public static string GetNewID(string ID)
        {
            return qPrefNEW_RECORD + ID;
        }

        public static string GetNewID()
        {
            return qPrefNEW_RECORD + Guid .NewGuid ().ToString ();
        }

        public static AgencyEntity CurrentAgency
        {
            get
            {

                return wsAgency.GetAgency();
            }
        }

        public static Employeer CurrentEmployeer
        {
            get
            {
                wsAgency ws = new wsAgency();
                return ws.GetCurrentEmployeer();
            }
        }
                 
        public static ProviderEntity  CurrentProvider
        {
            get
            {
                return ProviderEntity.GetProvider();
            }
        }
    }
}
